
package at.sphinx.androgen.restweb;

import java.util.Date;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

import at.sphinx.androgen.transferobjects.Person;

@Path("restwebtwo")
public class Restwebtwo {
    @SuppressWarnings("unused")
    @Context
    private UriInfo context;

    /**
     * Default constructor. 
     */
    public Restwebtwo() {
    }


    @GET
    @Produces("application/json")
    public Person getJsonDefault() {
    	
    	Person p1 = new Person();
    	p1.setLastname( "Default");
    	p1.setFirstname( "Default");
    	p1.setId( "1");
    	p1.setDob( new Date());
    	return p1;
    }    
    /**
     * @return an instance of Person
     */
    @GET
    @Produces("application/json")
    @Path("TNT")
    public Person getJson() {
    	
    	Person p1 = new Person();
    	p1.setLastname( "Tri Nitro");
    	p1.setFirstname( "toluol");
    	p1.setId( "2");
    	return p1;
    }
    
    @GET
    @Produces("application/xml")
    @Path("XML")    
    public Person getJsonXML() {
    	Person p1 = new Person();
    	p1.setLastname( "--- XML ---");
    	p1.setFirstname( "Touol");
    	p1.setId( "3");
    	return p1;
    }
    
    @GET
    @Produces({"application/xml", "application/json"})
    @Path("XMLJSON")    
    public Person getJsonXMLorJSON() {
    
    	
    	Person p1 = new Person();
    	p1.setLastname( "--- XMLJSON ---");
    	p1.setFirstname( "XMLJSON");
    	p1.setId( "4");
    	return p1;
    }

    @GET
    @Produces("application/json")
    @Path("withPID/{id}")      
    public Person getJsonParam(@PathParam("id") String requestedId ) {
    	
    	Person p1 = new Person();
    	p1.setLastname( "--- withPID: [" + requestedId +  "] ---");
    	p1.setFirstname( p1.getLastname());
    	p1.setId(requestedId);
    	return p1;
    }
    
    
    /**
     * @param content representation for the resource
     * @return an HTTP response with content of the updated or created resource.
     */
    @PUT
    // @Consumes({"application/json", "application/xml"})
    @Consumes("application/json")    
    @Path("putPerson/{id}")          
    public void putJson(@PathParam("id") String id, Person person) {
    	
    	System.out.println("Restwebtwo.putJson(): " + person.toString() ); 
    }

}





